home *** CD-ROM | disk | FTP | other *** search
- #include<exec/libraries.h>
- #include<intuition/intuition.h>
- #include<utility/tagitem.h>
- #include<graphics/text.h>
- #include<graphics/rastport.h>
-
- #include<string.h>
-
- #include<clib/exec_protos.h>
- #include<clib/graphics_protos.h>
- #include<clib/intuition_protos.h>
- #include<clib/layers_protos.h>
-
- struct Library* GfxBase;
- struct Library* IntuitionBase;
- struct Library* LayersBase;
-
- /* Need to give prototypes for our functions */
- void handleIDCMP(struct Window*);
- int setClip(struct Window*);
- void removeClip(struct Window*);
-
- void main()
- {
- /* Open libraries... */
- if(GfxBase = OpenLibrary("graphics.library",36))
- {
- if(IntuitionBase = OpenLibrary("intuition.library",36))
- {
- if(LayersBase = OpenLibrary("layers.library",36))
- {
- /* Open our window */
- struct Window* win;
- if(win = OpenWindowTags(NULL,
- WA_Left, 20,
- WA_Top, 20,
- WA_Width, 200,
- WA_Height, 100,
- WA_Flags, WFLG_CLOSEGADGET | WFLG_DRAGBAR | WFLG_REPORTMOUSE,
- WA_IDCMP, IDCMP_CLOSEWINDOW | IDCMP_MOUSEBUTTONS | IDCMP_MOUSEMOVE,
- TAG_DONE, 0))
- {
- /* If window opened, set clip region */
- if(setClip(win))
- {
- /* Now handle messages */
- handleIDCMP(win);
- removeClip(win);
- }
- CloseWindow(win);
- }
- CloseLibrary(LayersBase);
- }
- CloseLibrary(IntuitionBase);
- }
- CloseLibrary(GfxBase);
- }
- }
-
- /* Our message handling code */
- void handleIDCMP(struct Window* win)
- {
- char* text = "Hello World!";
- int going = TRUE;
- int drawing = FALSE;
- UBYTE pen = 1;
- SetDrMd(win->RPort, JAM1);
- while(going)
- {
- struct IntuiMessage* intuimsg;
- /* Wait for messages to arrive */
- WaitPort(win->UserPort);
- /* Messages have arrived: loop through all of them */
- while(intuimsg = (struct IntuiMessage*)GetMsg(win->UserPort))
- {
- /* Act on this message... */
- switch(intuimsg->Class)
- {
- case IDCMP_MOUSEBUTTONS:
- switch(intuimsg->Code)
- {
- case SELECTDOWN:
- drawing = TRUE;
- break;
- case SELECTUP:
- drawing = FALSE;
- break;
- }
- /* Omit the break to draw on click, too */
- break;
- case IDCMP_MOUSEMOVE:
- if(drawing)
- {
- /* Try changing colour using something like this: */
- SetAPen(win->RPort, pen++);
- /* Or this: */
- /* SetAPen(win->RPort, (UBYTE)(intuimsg->MouseY / 8)); */
- /* Or something of your own invention... */
- Move(win->RPort, intuimsg->MouseX, intuimsg->MouseY);
- Text(win->RPort, text, strlen(text));
- }
- break;
- case IDCMP_CLOSEWINDOW:
- going = FALSE;
- break;
- }
- /* Reply when finished with message */
- ReplyMsg((struct Message*)intuimsg);
- }
- }
- }
-
- /* Set a clip region on internal part of window */
- int setClip(struct Window* win)
- {
- /* Make a new region */
- struct Region* reg;
- if(reg = NewRegion())
- {
- /* Make a rectangle that describes the inside of the window */
- struct Rectangle rect;
- rect.MinX = win->BorderLeft;
- rect.MinY = win->BorderTop;
- rect.MaxX = win->Width - win->BorderRight - 1;
- rect.MaxY = win->Height - win->BorderBottom - 1;
- /* Make the region equal to this rectangle */
- if(OrRectRegion(reg, &rect))
- {
- /* Set the clip region on the window's layer */
- InstallClipRegion(win->WLayer, reg);
- /* Say we succeeded */
- return TRUE;
- }
- else
- {
- /* Failed to set region, so delete it */
- DisposeRegion(reg);
- }
- }
- /* If we get this far they we've failed */
- return FALSE;
- }
-
- /* Remove the clip region from a window */
- void removeClip(struct Window* win)
- {
- struct Region* reg;
- if(reg = InstallClipRegion(win->WLayer, NULL))
- {
- /* If a clip region is installed it's our new one, so delete it */
- DisposeRegion(reg);
- }
- }
-
-